<template>
	<view class="container">
		<view class="addBox flex-ac" @click="chooseCar">
			<image src="../../../static/img/addCar.png" mode=""></image>
			<view>选择车辆</view>
		</view>
		<view class="carList">
			<view class="item" v-for="(item, index) in list" :key="index">
				<image class="icon-car" src="../../../static/img/car.png" mode="aspectFill"></image>
				<view class="cell flex-ac">
					<view style="font-size: 30rpx;">{{item.carNo || ''}}/{{getDictName(item.carType)}} </view>
					<view class="label" v-if='item.type == 1'>自有车辆</view>
					<view class="label2" v-if='item.type == 2'>外调车辆</view>
				</view>
				<view class="cell flex-ac">
					<view>{{item.driverName || ''}}-{{item.driverPhone || ''}}</view>
				</view>
				<view class="cell flex-ac">
					<view v-if="item.status == 1">状态：空闲</view>
					<view v-if="item.status == 2">状态：运输中</view>
					<view v-if="item.status == 3">状态：休假</view>
					<view v-if="item.status == 4">状态：维修</view>
				</view>
				<view class="cell flex-ac">
					<view>空闲时间：{{item.idleTime || ''}}</view>
				</view>
				<view class="shanchuBox" @click="delCar(index)">
					<image src="../../../static/img/shanchu.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="foot">
			<view class="btnBox flex-ac">
				<view class="btn-1 middle" @click="submit">确定</view>
			</view>
			<x-botSpace></x-botSpace>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				list: [],
				dict: []
			}
		},
		onLoad(opt) {
			if (opt) console.log('opt:', opt)
			this.id = opt.id
			this.getDict()
		},
		methods: {
			submit() {
				if (this.list.length == 0) {
					this.$Toast.message('请选择车辆')
					return
				} else {
					this.$Net.post('/order/dispatch', {
						id: this.id,
						carIdList: this.list.map(el => {
							return el.id
						}),
					}).then(res => {
						this.$Toast.messageIcon('操作成功')
						setTimeout(() => {
							this.$Jump.Back(1)
						}, 1000);
					})
				}
			},
			getData(arr) {
				this.list = arr
				this.$forceUpdate()
			},
			delCar(index) {
				this.list.splice(index, 1)
			},
			getDictName(id) {
				return this.dict.find(item => item.code == id).name || ''
			},
			// 获取字典数据
			getDict() {
				this.$Net.get('/sysDict/code/car_type').then(res => {
					console.log('字典数据:', res)
					this.dict = res.data
				})
			},
			chooseCar() {
				this.$Jump.Open('../selCar/selCar')
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
</style>

<style lang="scss" scoped>
	// @import './style.scss';
	.carList {
		width: 100%;
		padding-bottom: 120rpx;

		.item {
			position: relative;
			padding: 28rpx;
			padding-left: 90rpx;
			width: 100%;
			border-bottom: 1rpx solid #f7f7f7;
			font-size: 24rpx;

			.icon-car {
				width: 50rpx;
				height: 50rpx;
				position: absolute;
				top: 30rpx;
				left: 25rpx;
			}

			.shanchuBox {
				padding: 40rpx;
				position: absolute;
				right: 10rpx;
				top: 50%;
				transform: translateY(-50%);

				image {
					width: 40rpx;
					height: 40rpx;
				}
			}

			.cell {
				margin-bottom: 8rpx;
			}

			.label {
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #f2f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}

			.label2 {
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #a1f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
		}
	}

	.addBox {
		width: 100%;
		height: 110rpx;
		padding: 0 30rpx;
		font-size: 28rpx;
		color: #1F82FE;
		background-color: #f7f7f7;

		image {
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}

	.foot {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding: 30rpx;

		.btnBox {
			width: 100%;

			.btn-1 {
				flex: 1;
				height: 90rpx;
				background: #1684FC;
				border-radius: 10rpx;
				color: #ffffff;
				font-size: 34rpx;
			}

			.btn-2 {
				flex: 1;
				height: 90rpx;
				border: 1px solid #1684FC;
				border-radius: 10rpx;
				color: #1684FC;
				font-size: 34rpx;
			}
		}
	}
</style>